<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <search ref="search" :config="searchConfig" @search="search" @getHeight="getHeight"/>
    <!-- table区域-begin -->
    <div class="page_table">
      <vxe-grid
        ref="xGrid"
        :border="true"
        :resizable="true"
        :showOverflow="true"
        size="mini"
        :loading="loading"
        :height="pageHeight-seachHeight-90"
        :align="left"
        :columns="columns"
        :data="dataSource"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        :toolbar-config="tableToolbar"
        :checkbox-config="checkboxConfig"
        v-bind="vexConfig"
        @checkbox-change="selectChangeEvent"
        @checkbox-all="selectChangeEvent"
      >
        <template #toolbar_buttons>
          <div class="table-operator">
            <!-- <a-button v-has="'SfaVisitGroupList:add'" type='primary' @click='handleAdd'>新增</a-button> -->
            <a-button type="primary" @click="handleAdd">新增</a-button>
            <a-button v-has="'SfaVisitGroupList:delete'" @click="batchDel">删除</a-button>
            <!--            <a-button type="primary" >导入</a-button>-->
            <a-button v-has="'SfaVisitGroupList:export'" type="primary" @click="downExportXls('visit_group')">导出
            </a-button>
          </div>
        </template>
        <template #detail="{ row,rowIndex }">
          <a @click="handleDetail(row)">{{ row.groupCode }}</a>
        </template>

        <template #action="{ row,rowIndex }">
          <a v-has="'SfaVisitGroupList:update'" @click="handleEdit(row)">编辑</a>
          <a-divider type="vertical"/>
          <a href="javascript:" @click='handleBusiness("线路组",row)'>日志</a>
        </template>

        <template #status="{ row }">
          <a-switch :checked="row.status" size="small" @change="handleStatus(row,$event)"/>
        </template>
        <template #pager>
          <vxe-pager
            :layouts="['Total', 'PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump','Sizes', 'FullJump']"
            :currentPage.sync="ipagination.current"
            :page-size.sync="ipagination.pageSize"
            :total="ipagination.total"
            :pageSizes="ipagination.pageSizeOptions"
            @page-change="handlePageChange">
          </vxe-pager>
        </template>
      </vxe-grid>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <sfaVisitGroupEntity-modal ref="modalForm" @ok="modalFormOk"></sfaVisitGroupEntity-modal>
    <JSelectClientModal
      modal-width="90%"
      ref="JSelectClientModal"
      @ok="handelSave">
    </JSelectClientModal>
    <business-log ref="businessLog"></business-log>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import SfaVisitGroupEntityModal from './modules/SfaVisitGroupModal'
import { PageListMixin } from '@/mixins/PageListMixin'
import JSelectClientModal from '../../../components/cn-select-popup/JSelectClientModal'
import { postAction } from '../../../api/manage'

export default {
  name: 'SfaVisitGroupList',
  mixins: [PageListMixin],
  components: {
    SfaVisitGroupEntityModal, JSelectClientModal
  },
  data() {
    return {
      description: '线路组管理',
      id: '',
      // 查询区域
      searchConfig: [
        {
          type: 'input',
          name: 'groupCode',
          placeholder: '线路组编码'
        },
        {
          type: 'input',
          name: 'groupName',
          placeholder: '线路组名称'
        },
        {
          type: 'input',
          name: 'fullName',
          placeholder: '对应人员名'
        },

      ],
      // 表头
      columns: [
        { type: 'checkbox', width: 50, fixed: 'left' },
        {
          title: '线路组编码',
          minWidth: 100,
          field: 'groupCode',
          slots: { default: 'detail' }
        },
        {
          title: '线路组名称',
          minWidth: 100,
          field: 'groupName'
        },
        {
          title: '人员编码',
          minWidth: 120,
          field: 'userName'
        },
        {
          title: '人员姓名',
          minWidth: 120,
          field: 'fullName'
        },
        {
          title: '线路岗位名称',
          minWidth: 120,
          field: 'visitPosName'
        },
        {
          title: '所属组织',
          minWidth: 120,
          field: 'visitOrgName'
        },
        {
          title: '创建人',
          minWidth: 80,
          field: 'createName'
        },
        {
          title: '创建时间',
          minWidth: 80,
          field: 'createTime'
        },
        {
          title: '更新人',
          minWidth: 80,
          field: 'updateName'
        },
        {
          title: '更新时间',
          minWidth: 80,
          field: 'updateTime'
        },
        // {
        //   title: '状态',
        //   minWidth:80,
        //   field: 'status'
        // },
        {
          title: '操作',
          minWidth: 100,
          fixed: 'right',
          slots: { default: 'action' }
        }
      ],
      isorter: {
        permflag: 'visit_group_page_impl'
      },
      url: {
        list: window._CONFIG['domianSfaURL'] + '/visit/sfaVisitGroupController/findPageList',
        delete: window._CONFIG['domianSfaURL'] + '/visit/sfaVisitGroupController/delete',
        detail: window._CONFIG['domianSfaURL'] + '/small/visit/sfaVisitGroupEntity/getInfo',
        deleteBatch: window._CONFIG['domianSfaURL'] + '/visit/sfaVisitGroupController/deleteBatch',
        exportXlsUrl: window._CONFIG['domianSfaURL'] + 'visit/sfaVisitGroupController/exportXls',
        importExcelUrl: window._CONFIG['domianSfaURL'] + 'visit/sfaVisitGroupController/importExcel',
      },
    }
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  methods: {
    handelSave(clients, groupCode) {
      const record = { groupCode: groupCode }
      record.clients = clients
      var that = this
      postAction(window._CONFIG['domianSfaURL'] + '/visit/sfaVisitGroupClientController/saveOrUpdate', record).then(async (res) => {
        if (res.success) {
          that.$message.success(res.message)
          await this.loadData()
          this.$refs.JSelectClientModal.close()
        } else {
          this.$message.warning(res.message)
        }
      }).finally(() => {
        this.$refs.JSelectClientModal.confirmLoading = false
      })
    },
    async handleClientModal(record) {
      if (this.selectedRowKeys.length != 1) {
        this.$message.warning('请选择一条记录！')
        return
      }
      this.$refs.JSelectClientModal.showModal(this.selectionRows[0].groupCode, this.selectionRows[0].visitPosCode)
    },
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>